//
//  CityScenerySenViewController.m
//  DZZTravel
//
//  Created by 赵国栋 on 16/7/16.
//  Copyright © 2016年 Eason. All rights reserved.
//

#import "CityScenerySenViewController.h"

@interface CityScenerySenViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong)NSMutableArray *array;
@property (nonatomic ,strong)UITableView *tableView;


@property (nonatomic ,strong)NSString *coverPic;
@property (nonatomic ,strong)NSString *cityName;

@property (nonatomic ,strong)NSString *address;
@property (nonatomic ,strong)NSString *openTime;

@property (nonatomic ,strong)NSString *intro;

@property (nonatomic ,strong)NSMutableArray *Firastarray;


@end


@implementation CityScenerySenViewController
+ (instancetype)shareDefalut{
    static   CityScenerySenViewController*handle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        handle = [[CityScenerySenViewController   alloc]init];
    });
    return handle;
}


- (NSMutableArray *)Firastarray{
    if (!_Firastarray) {
        _Firastarray = [NSMutableArray array];
    }
    return _Firastarray;
}

- (NSMutableArray *)array{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, kWidth, kheight) style:UITableViewStylePlain];
      
        _tableView.delegate = self;
        _tableView.dataSource =self;
    }
    return _tableView;
}


- (void)viewDidLoad {
    
    [super viewDidLoad];
    [passValueForCell shareDefalut].cityID = self.city.scenicId;
    
    //注册cell
    [self.tableView registerClass:[FirstCollectionViewCell class] forCellReuseIdentifier:@"qqq"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"SecondCollectionViewCell" bundle:nil] forCellReuseIdentifier:@"SecondCollectionViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ThreeTableViewCell" bundle:nil] forCellReuseIdentifier:@"ThreeTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"FourTableViewCell" bundle:nil] forCellReuseIdentifier:@"FourTableViewCell"];
    
    [self.view addSubview:self.tableView];
    
    
    NSArray *array = @[@"1",@"1",@"1",@"1"];
    NSArray *arrayy = @[@"1",@"1",@"1",@"1",@"1"];
    self.array = @[array,arrayy].mutableCopy;
    
    
   
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 1) {
        HeadTitleView *head = [[HeadTitleView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 40)];
        head.backgroundColor = [UIColor lightGrayColor];
        return head;
    }
    return nil;
}



- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0&&indexPath.section==0) {
        return KCELLHEIGHT;
    }else if (indexPath.row==1&&indexPath.section==0){
    return 100;
    }else if (indexPath.row==2&&indexPath.section==0){
        return 300;
    }
    return 200;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.array[section] count];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.array.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0 && indexPath.section==0) {
        FirstCollectionViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"qqq" forIndexPath:indexPath];
        
        [self creatCellWithblock:^{
            [cell.image sd_setImageWithURL:[NSURL URLWithString:self.coverPic]];
            cell.lable.text = self.cityName;
        }];
        [cell.picBtn addTarget:self action:@selector(picBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [cell.introduceBtn addTarget:self action:@selector(introduceBtnAction) forControlEvents:UIControlEventTouchUpInside];
        return cell;
        
    }else if(indexPath.row==1 && indexPath.section==0){
        
        SecondCollectionViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SecondCollectionViewCell" forIndexPath:indexPath];
          [self creatCellWithblock:^{
              cell.openTime.text = self.openTime;
              cell.adress.text = self.address;
          }];
        return cell;
        
    }else if (indexPath.row==2 && indexPath.section==0){
    ThreeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThreeTableViewCell" forIndexPath:indexPath];
       
        return cell;
    }
    FourTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FourTableViewCell" forIndexPath:indexPath];
  
   
    return cell;
}




- (void)creatCellWithblock:(void(^)())block{
    
    [RequestManager fectDataWithUrl:[NSString stringWithFormat:@"http://apiphp.yaochufa.com/portal/scenic/ScenicDetail430?channel=AppStore&id=%@&imei=3BB694A0-037E-406A-8F2B-0852448416B6&lang=app&machineCode=3BB694A0-037E-406A-8F2B-0852448416B6&machineType=0&system=ios&version=5.2.3",self.city.scenicId] parameter:@{} method:@"GET" compelet:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        self.coverPic = dic[@"content"][@"coverPic"];
        self.cityName = dic[@"content"][@"cityName"];
        
        self.address = dic[@"content"][@"address"];
        self.openTime = dic[@"content"][@"openTime"];
        
        self.intro = dic[@"content"][@"intro"];
        
     
        
       
    } upDateUI:^{
        block();
        [self.tableView reloadData];
    }];

}


#pragma mark---------------------cell按钮事件------------------

- (void)picBtnAction{
    PicViewController *picVC = [PicViewController new];
    picVC.city = self.city;
    picVC.cityID = self.city.scenicId;
    [self presentViewController:picVC animated:NO completion:nil];
   
}


- (void)introduceBtnAction{
    IntroduceViewController *IntroduceVC =[IntroduceViewController new];
    [self creatCellWithblock:^{
        IntroduceVC.introuduce.text = self.intro;
    }];
    [self presentViewController:IntroduceVC animated:NO completion:nil];
    
}




@end
